PopupField = Ext.extend(Ext.form.TriggerField,  {  //TriggerField, ComboBox
    triggerClass : "x-form-search-trigger",
    // defaultAutoCreate : {tag: "input", type: "text", name: "test", autocomplete: "off"},

    initComponent : function(){
        PopupField.superclass.initComponent.call(this);
    },
    
    initEvents: function() {
        PopupField.superclass.initEvents.call(this);
    },
    
    onDestroy: function(){
        Ext.destroy(this.menu, this.keyNav);
        PopupField.superclass.onDestroy.call(this);
    },
    
    validateBlur: function() {
        return !this.menu || !this.menu.isVisible();
    },

    onTriggerClick: function() {
        if(this.disabled){
            return;
        }
        this.popupWindow();
        /*
        if(this.menu == null){
            this.menu = new Ext.menu.DateMenu({
                hideOnClick: false,
                focusOnSelect: false
            });
        // this.onFocus();
        }*/
    },
    
    popupWindow: function() {
        // implemented in sub class
    }
    
});

Ext.reg('popupfield', PopupField);

CustomerPopupField = Ext.extend(PopupField, {
    fieldLabel: '客户',
    name: "customer",
    valueField: "id",
    displayField: "name",
    url: "../../popup/extjs/CustomersJson.bl",
    fields: ['id', 'code', 'name'],
    queryParam: "customerSO.codeName",
    // store: store,
    typeAhead: false,
    loadingText: 'Searching...',
    minChars: 2,
    pageSize: 10,
    // tpl: resultTpl,
    forceSelection: true,
    itemSelector: 'div.search-item',
    
    initComponent: function() {
        var customerStore = StoreManager.getCustomerStore();
        this.store = customerStore;
        /*this.store = new Ext.data.JsonStore({
            root: 'dataList',
            totalProperty: 'totalCount',
            id: 'id',
            remoteSort: true,
            fields: this.fields,
            proxy: new Ext.data.HttpProxy({
                url: this.url
            })
        });*/
        this.tpl = new Ext.XTemplate(
            '<tpl for="."><div class="search-item">',
                '<span>{name}</span>',
            '</div></tpl>'
        );
        
        CustomerPopupField.superclass.initComponent.call(this);
    }, 
    
    popupWindow: function() {
        // alert(this.getValue());
        var popup = PopupManager.getCustomerPopup(this.store);
        popup.on("datachanged", this.fillBackData, this);
        
        popup.store.baseParams = {"customerSO.codeName": ""};
        // popup.store.reload();

        popup.show();
        popup.load();
    },
    
    fillBackData: function(data) {
        Ext.getCmp("customerId").setValue(data.id);
        Ext.getCmp("customer").setValue(data.name);
        this.fireEvent('change'); 
    }
    
});

NzoneField = Ext.extend(PopupField,  {    
    initComponent: function() {
        /*this.store = new Ext.data.JsonStore({
            root: 'dataList',
            totalProperty: 'totalCount',
            id: 'id',
            remoteSort: true,
            fields: this.fields,
            proxy: new Ext.data.HttpProxy({
                url: this.url
            }),
            baseParams: {
                customerId: 60760
            }
        });
        this.tpl = new Ext.XTemplate(
            '<tpl for="."><div class="search-item">',
                '<span>{name}</span>',
            '</div></tpl>'
        );*/
        
        NzoneField.superclass.initComponent.call(this);
    }, 
    
    popupWindow: function() {
       /*Geni.Popup.showWindow({
            url: "../../module/naturalZone/ZoneSelect.bl?isNeedLimit=true",
            title: '选择区域',
            width: 300,
            height: 400,
            returnCallback: function(data) {
                Ext.getCmp("senderAddressZoneId").setValue(data.key);
                Ext.getCmp("senderAddressZoneName").setValue(data.value);
            }
        });*/
        // var popup = PopupManager.getSenderPopup();
        // popup.show();
    }
});

Ext.reg('nzonefield', NzoneField);



PopupComboBox = Ext.extend(Ext.form.ComboBox,  {  //TriggerField, ComboBox
    triggerClass : "x-form-search-trigger",
    // defaultAutoCreate : {tag: "input", type: "text", name: "test", autocomplete: "off"},

    initComponent : function(){
        PopupComboBox.superclass.initComponent.call(this);
    },
    
    initEvents: function() {
        PopupComboBox.superclass.initEvents.call(this);
    },
    
    onDestroy: function(){
        Ext.destroy(this.menu, this.keyNav);
        PopupComboBox.superclass.onDestroy.call(this);
    },
    
    validateBlur: function() {
        return !this.menu || !this.menu.isVisible();
    },

    onTriggerClick: function() {
        if(this.disabled){
            return;
        }
        this.popupWindow();
    },
    
    popupWindow: function() {
        // implemented in sub class
    },
	
	loadingText:"正在查询...",
	selectOnFocus: true,
    forceSelection: true,
	editable: true
    
});

Ext.reg('popupcombo',PopupComboBox);


/**
 * 
 * @class Ext.Viewport
 * @extends Ext.Container
 */
Ext.ViewportBest = Ext.extend(Ext.Container, {

    initComponent : function() {
        Ext.Viewport.superclass.initComponent.call(this);
        document.getElementsByTagName('html')[0].className += ' x-viewport';
        this.el = Ext.getCmp("content");
        this.el.setHeight = Ext.emptyFn;
        this.el.setWidth = Ext.emptyFn;
        this.el.setSize = Ext.emptyFn;
        this.el.dom.scroll = 'no';
        this.allowDomMove = false;
        this.autoWidth = true;
        this.autoHeight = true;
        Ext.EventManager.onWindowResize(this.fireResize, this);
        this.renderTo = this.el;
    },

    fireResize : function(w, h){
        this.onResize(w, h, w, h);
    }
});
Ext.reg('viewportbest', Ext.Viewport);